package com.john.utils.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.john.utils.http.HttpHeader;
import com.john.utils.http.HttpSend;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 地图相关
 */
public class MapRelated {
    /**
     * 根据地址获取经纬度
     * @return
     */
    public static String showPicker(String address){
        address = address.trim().replace(" ", "");
        String url = "https://restapi.amap.com/v3/place/text?s=rsv3&children=&key=8325164e247e15eea68b59e89200988b&page=1&offset=10&city=520600&language=zh_cn&callback=jsonp_755771_&platform=JS&logversion=2.0&sdkversion=1.3&appname=https://lbs.amap.com/console/show/picker&csid=C9D2A512-FB53-4216-89E5-0A61FA24B71D&keywords="+address;
        HttpSend httpSend = HttpSend.custom();	//实例化
        httpSend.setHttpsRequest(true);
        httpSend.setHttpsShowLog(true);
        HttpHeader headers = HttpHeader.custom();
        httpSend.setRequestHeaders(headers.build());
        JSONObject result = httpSend.sendGet(url).execute();
        if(result != null && result.getIntValue("status") == 200){
            String resultContent = result.getString("resultData").replace("jsonp_755771_(", "").replace(")", "");
            JSONObject jsonObject = JSONObject.parseObject(resultContent);
            if(jsonObject.containsKey("pois")){
                JSONArray array = jsonObject.getJSONArray("pois");
                return array.getJSONObject(0).getString("location");
            }
            return jsonObject.toJSONString();
        }
        return "";
    }

    public static void showPickers(String appId,String secret){
        String url = "https://test.dulaing.fe-cred.com/rxapi/api/hospital/outpatientPrescriptionUpload";
        HttpSend httpSend = HttpSend.custom();	//实例化
        HttpHeader headers = HttpHeader.custom();
        httpSend.setRequestHeaders(headers.build());
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("optType", "1");
        params.put("DRUG_INFO",new Object());
        params.put("DRUG_LIST",new ArrayList<Object>());
        httpSend.setParameter(JSON.toJSONString(params));
        httpSend.setHttpsShowLog(true);
        JSONObject result = httpSend.sendPost(url).execute();
        if(result != null){
            System.out.println(result.toJSONString());
        }
    }
}
